﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;


namespace 护士工作站
{
    public partial class 密码修改 : Form
    {
        public 密码修改()
        {
            InitializeComponent();
        }

        private void button1_确定_Click(object sender, EventArgs e)
        {
            if (tb_ysmm.Text.Trim() != UserHelper.NurPassword)
            {
                MessageBox.Show("原始密码错误！");
                tb_ysmm.Focus();
                return;

            }
            if (tb_xmm.Text.Trim() =="")
            {
                MessageBox.Show("新密码不能为空，请输入！");
                tb_xmm.Focus();
                return;
            }
            if (tb_qrmm.Text.Trim() != tb_xmm.Text.Trim())
            {
                MessageBox.Show("两次密码不一致，请重新输入！");
                tb_qrmm.Focus();
                return;
             }
             using (SqlConnection conn = new SqlConnection(DBHelper.connString))
            {
                string sql = string.Format("update [Nurse]set NurPassword='{0}'where NurNo='{1}' ", tb_xmm.Text.Trim(),UserHelper.NurNo);
                SqlCommand cmd = new SqlCommand(sql, conn);
                conn.Open();
                int n = Convert.ToInt32(cmd.ExecuteNonQuery());
                if (n != 1)
                {
                    MessageBox.Show("修改密码失败！");
                }
                else
                {
                    MessageBox.Show("修改密码成功！");
                    UserHelper.NurPassword = tb_xmm.Text.Trim();
                }
            }
        }

        private void button2_取消_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
